*********************************************************
**     Actuals.do********************************** 
*This replicates Ashenfelter/Hosken, and applies their method*
*to rival brands.*************************************
*********************************************************
*define clusters of 6 months/region

clear
clear mata
clear matrix
set mem 400m
set more off
*use "K:\BE\Consumer_Product\weinberg_hosken_paper\restat_stuff\pass_thru\oil_data_1_2011.dta"
local path "c:/data/restat_12_9/analysis_data/"
local figurepath "c:/data/restat/figures/"
use "`path'oil_data_1_2011"
/*cd \Data\Hoskenpaper*/
cap log close
*log using "K:\BE\Consumer_Product\weinberg_hosken_paper\restat_stuff\pass_thru\oil_price_effects_final.log", replace
*keep if choiceset2==1

gen month=month(date)
gen year=year(date)
rename sale ASALE 
rename vol AVOL
rename brand BRAND
rename region REGION 
rename month MONTH
rename year YEAR
destring MONTH, replace
destring YEAR, replace
*drop week DAY type
collapse (sum) AVOL ASALE, by(BRAND REGION YEAR MONTH weight)
sort REGION BRAND YEAR MONTH
gen tyear=YEAR*100
gen t=tyear+MONTH
sort YEAR MONTH
merge YEAR MONTH using "`path'wti_monthly_for_oil.dta"
tab _merge
drop _merge
drop if t>200009



gen merged=t>=199900

/*Pre-trends here*/
gen month1=MONTH/2
replace month1=int(month1)
gen T=YEAR*100+month1
tab T,gen(T)
gen date=ym(YEAR,MONTH)
format date %tm

gen p_10w30=0
gen q_10w30=0
gen pl_10w30=0

label var p_10w30 "Pennzoil 10W30"
label var q_10w30 "Quaker State 10W30"
label var pl_10w30 "Private Label 10W30"

gen aprice=ASALE/AVOL
gen lprice=log(aprice)
gen lwti=log(wti_barrel)
*drop all data following 9/2000 due to error in iri data for 10w30 private label motor oil

/*create cluster*/

gen half_year=0
replace half_year=1 if MONTH>6

gen time1=YEAR*10+half_year
encode REGION,gen(region)
gen region_halfyear=time1*100+region
tab region_halfyear

keep if weight=="10W30"
gen BRAND_REGION=BRAND + REGION
encode BRAND_REGION,gen(brand_region)
tset brand_region t
sort brand_region t


xi: reg lprice  T1-T26 if (BRAND=="PENNZOIL" & weight=="10W30"), nocons
forval x=1/26{
	replace  p_10w30 =_b[T`x'] if T`x'==1
}



qui xi: reg lprice  T1-T26 if (BRAND=="QUAKER STATE" & weight=="10W30"), nocons
forval x=1/26{
	replace q_10w30=_b[T`x'] if T`x'==1
}


qui xi: reg lprice  T1-T26 if (BRAND=="PRIVATE LABEL" & weight=="10W30"), nocons
forval x=1/26{
	replace pl_10w30=_b[T`x'] if T`x'==1
}

sort date
twoway (line p_10w30 date if BRAND=="PENNZOIL" & weight=="10W30"&t<=200009, clcolor(gs0) lpattern("-.-.-."))||/*
*/||(line q_10w30 date if BRAND=="QUAKER STATE"& weight=="10W30"&t<=200009 , clcolor(gs0) lpattern("##--##"))/*
*/||(line pl_10w30 date if BRAND=="PRIVATE LABEL"& weight=="10W30"&t<=200009, clcolor(gs10)), /*
*/ytitle("log price($/Quart)") xline(467) text(.0 467 "Merger Consummated", orientation(vertical) placement(e)) graphregion(color(white)) bgcolor(white)


graph export "`figpath'OilPlot.eps", replace
	
/*Parallel pre-merger trend test*/


gen branded=1
replace branded=0 if BRAND=="PRIVATE LABEL"
gen t_b=t*(branded)

gen dd=branded*merged
gen b_lwti=branded*lwti


xi: reg lprice t t_b i.REGION*i.branded if (merged==0)&(weight=="10W30")&(BRAND=="PENNZOIL"|BRAND=="PRIVATE LABEL"), cluster(region_halfyear)
xi: reg lprice t t_b i.REGION*i.branded if (merged==0)&(weight=="10W30")&(BRAND=="QUAKER STATE"|BRAND=="PRIVATE LABEL"), cluster(region_halfyear)
xi: reg lprice t t_b i.REGION*i.branded if (merged==0)&(weight=="10W30")&(BRAND=="CASTROL GT X"|BRAND=="PRIVATE LABEL"), cluster(region_halfyear)
xi: reg lprice t t_b i.REGION*i.branded if (merged==0)&(weight=="10W30")&(BRAND=="HAVOLINE FORMULA 3"|BRAND=="PRIVATE LABEL"), cluster(region_halfyear)
xi: reg lprice t t_b i.REGION*i.branded if (merged==0)&(weight=="10W30")&(BRAND=="MOBIL"|BRAND=="PRIVATE LABEL"), cluster(region_halfyear)
xi: reg lprice t t_b i.REGION*i.branded if (merged==0)&(weight=="10W30")&(BRAND=="VALVOLINE MULTI VISCOSITY"|BRAND=="PRIVATE LABEL"), cluster(region_halfyear)




drop if t>199809&t<199904|t>200101

tab t


xi: reg lprice b_lwti lwti i.MONTH i.REGION*i.branded merged dd if (weight=="10W30")&(BRAND=="PENNZOIL"|BRAND=="PRIVATE LABEL"), cluster(region_halfyear)
xi: reg lprice b_lwti lwti i.MONTH i.REGION*i.branded merged dd if (weight=="10W30")&(BRAND=="QUAKER STATE"|BRAND=="PRIVATE LABEL"), cluster(region_halfyear)
xi: reg lprice b_lwti lwti i.MONTH i.REGION*i.branded merged dd if (weight=="10W30")&(BRAND=="CASTROL GT X"|BRAND=="PRIVATE LABEL"), cluster(region_halfyear)
xi: reg lprice b_lwti lwti i.MONTH i.REGION*i.branded merged dd if (weight=="10W30")&(BRAND=="HAVOLINE FORMULA 3"|BRAND=="PRIVATE LABEL"), cluster(region_halfyear)
xi: reg lprice b_lwti lwti i.MONTH i.REGION*i.branded merged dd if (weight=="10W30")&(BRAND=="MOBIL"|BRAND=="PRIVATE LABEL"), cluster(region_halfyear)
xi: reg lprice b_lwti lwti i.MONTH i.REGION*i.branded merged dd if (weight=="10W30")&(BRAND=="VALVOLINE MULTI VISCOSITY"|BRAND=="PRIVATE LABEL"), cluster(region_halfyear)





xi: reg lprice lwti i.MONTH i.REGION merged if (weight=="10W30")&(BRAND=="PENNZOIL"), cluster(region_halfyear)
xi: reg lprice lwti i.MONTH i.REGION merged if (weight=="10W30")&(BRAND=="QUAKER STATE"), cluster(region_halfyear)
xi: reg lprice lwti i.MONTH i.REGION merged if (weight=="10W30")&(BRAND=="CASTROL GT X"), cluster(region_halfyear)
xi: reg lprice lwti i.MONTH i.REGION merged if (weight=="10W30")&(BRAND=="HAVOLINE FORMULA 3"), cluster(region_halfyear)
xi: reg lprice lwti i.MONTH i.REGION merged if (weight=="10W30")&(BRAND=="MOBIL"), cluster(region_halfyear)
xi: reg lprice lwti i.MONTH i.REGION merged if (weight=="10W30")&(BRAND=="VALVOLINE MULTI VISCOSITY"), cluster(region_halfyear)
xi: reg lprice lwti i.MONTH i.REGION merged if (weight=="10W30")&(BRAND=="PRIVATE LABEL"), cluster(region_halfyear)

log close




